<?php
class Admin_Form_VanBanForm extends Zend_Form{
	public function __construct($option = null){
		parent::__construct($option);
		
		$this->setName('vanban');
		
		$tenvanban = new Zend_Form_Element_Text('tenvanban');
		$tenvanban->setLabel('Tên văn bản: ')
							->setRequired(true)
							->addFilter('HTMLEntities');
		
		$maloaivanban = new Zend_Form_Element_Select('maloaivanban');
		$maloaivanban->setLabel('Loại văn bản: ')
								->setRequired(true);
		$loaivanbanMapper = Library_Model_LoaiVanBanMapper::getInstance();
		$loaivanbans = $loaivanbanMapper->loaivanbanList();
		
		foreach ($loaivanbans as $loaivanban){
			$maloaivanban->addMultiOption(
							$loaivanban->getId(), $loaivanban->getTenloai());
		}
		
		$ngaybanhanh = new Zend_Form_Element_Text('ngaybanhanh');
		$ngaybanhanh->setLabel('Ngày ban hành văn bản: ')
								->setRequired(true)
								->addValidator('Date', true, array('format' => 'yyyy-MM-dd'));
		$ngaycohieuluc = new Zend_Form_Element_Text('ngaycohieuluc');
		$ngaycohieuluc->setLabel('Ngày có hiệu lực: ')
								->setRequired(true)
								->addValidator('Date', true, array('format' => 'yyyy-MM-dd'));
		
		$machinhanh = new Zend_Form_Element_Select('machinhanh');
		$machinhanh->setLabel('Tên chi nhánh: ')
		->setRequired(true);
		$chinhanhMapper = Library_Model_ChiNhanhMapper::getInstance();
		$tenchinhanhs = $chinhanhMapper->chinhanhList();
		
		foreach ($tenchinhanhs as $tenchinhanh){
			$machinhanh->addMultiOption(
					$tenchinhanh->getId(), $tenchinhanh->getTenchinhanh());
		}
		
		$maphongban = new Zend_Form_Element_Select('maphongban');
		$maphongban->setLabel('Tên phòng ban: ')
		->setRequired(true);
		$phongbanMapper = Library_Model_PhongBanMapper::getInstance();
		$tenphongbans = $phongbanMapper->phongbanList();
		
		foreach ($tenphongbans as $tenphongban){
			$maphongban->addMultiOption(
					$tenphongban->getId(), $tenphongban->getTenphongban());
		}
		
		$manhom = new Zend_Form_Element_Select('manhom');
		$manhom->setLabel('Tên nhóm: ')
		->setRequired(true);
		$nhomvanbanMapper = Library_Model_NhomVanBanMapper::getInstance();
		$tennhoms = $nhomvanbanMapper->nhomvanbanList();
		
		foreach ($tennhoms as $tennhom){
			$manhom->addMultiOption(
					$tennhom->getId(), $tennhom->getTennhom());
		}
		
		$trangthai = new Zend_Form_Element_Radio('trangthai');
		$trangthai->setLabel('Trạng thái: ')
						->setRequired(true);
		$trangthai->setMultiOptions(array(
							'1' => 'Mở',
							'0' => 'Không'));				
		
		$doquantrong = new Zend_Form_Element_Radio('doquantrong');
		$doquantrong->setLabel('Độ quan trọng: ')
								->setRequired(true);
		$doquantrong->setMultiOptions(array(
							'1' => 'Rất quan trọng',
							'2' => 'Quan trọng',
							'3' => 'Bình thường'));
		
		$nguoiduyet = new Zend_Form_Element_Text('nguoiduyet');
		$nguoiduyet->setLabel('Người duyệt: ')
							->setRequired(true)
							->addFilter('HTMLEntities');
		
		$noidung = new Zend_Form_Element_Textarea('noidung');
		$noidung->setLabel('Nội dung: ')
								->setRequired(true)
								->setAttribs(array(
														'cols' => '60',
														'rows' => '20'));		
		
		$fileDestination = realpath(APPLICATION_PATH . '/../public/docs/vanban');
		$tentaptin = $this->createElement('file','tentaptin', array(
				'label' => 'Tên tập tin: ',
				'required' => true,
				'destination' => $fileDestination,
				'validators' => array(
						array('Count', false, array(1)),
						array('Size', false, array(10485767*5)),
						//array('Extension', false, array('jpg,png,gif')),
						array('Extension', false, array('pdf, doc, ')),
				),
		));
		
		$duyet = $this->createElement('select', 'Duyet', array(
				'required'   => true,
				'label'      => 'Mặc định hiển thị',
				'multiOptions' => array('1' => 'Có','0' => 'Không'),
		));
		
		$this->addElements(array($tenvanban, $maloaivanban, $ngaybanhanh,$manhom, 
													$ngaycohieuluc, $machinhanh, $maphongban, $trangthai, $doquantrong, 
													 $nguoiduyet, $noidung,
													$duyet, $tentaptin));
	}
}